<?php


function get_report_name( $key = '')
{
	$CI =& get_instance();

	$reports = $CI->config->item('reports');

	foreach($reports as $k=>$v)
	{
		if( array_key_exists($key, $v) )
		{
			return $reports[$k][$key];
		}
	}

	return $key;
}

 function date_range_options($sel =""){

 	
 	$sel = (!empty($sel))?$sel:'30';

    $cases = array('15' => 'Last 15 days', '30' => 'Last 30 days','45' => 'Last 45 days','60' => 'Last 60 days','90' => 'Last 90 days');
 	
 	$start = date('Y-m-d H:i');

 	$str ="";

    foreach($cases as $case => $label) {

    	$end = date('Y-m-d H:i',strtotime('-'.$case.' days',strtotime($start)));

    	$selected = ($sel == $case)?'selected=selected':'';
    	
        $str .= "<option value='$case' highdateval ='{$start}' $selected lowdateval = '{$end}'>$label</option>";
      
    }

    $selected = ($sel == 'custom')?'selected=selected':'';
    $str .="<option value='custom' $selected>Custom</option>";

    return $str;  	
 }	


 function get_DB_Date( $date = '', $format = 'Y-m-d H:i:s')
 {
 	if( $date == '')
 		$time = time();
 	else
 	{
 		$date = preg_replace(array('/T/','/Z/'), array(' ',''), $date);
 		$time =	strtotime($date);
 	}
 	
 	return date($format, $time); 	
 	
 }
 
 
?>